#include "WindowSurface.h"

mini_engine::WindowSurface *mini_engine::WindowSurface::m_windowSurface = nullptr;
VkSurfaceKHR mini_engine::WindowSurface::surface = nullptr;

mini_engine::WindowSurface::WindowSurface()
{
}

void mini_engine::WindowSurface::createWindowSurface()
{
    cout << "create surface" << endl;
    VkSurfaceKHR vkSurface;
    if (glfwCreateWindowSurface(Instance::instance, InitWindow::window, nullptr, &vkSurface) != VkResult::VK_SUCCESS)
    {
        throw std::runtime_error("failed to create window surface!");
    }
    WindowSurface::surface = vkSurface;
}

mini_engine::WindowSurface *mini_engine::WindowSurface::getWindowSurface()
{
    if (m_windowSurface == nullptr)
    {
        m_windowSurface = new WindowSurface();
        static WindowSurfaceDestruction windowSurfaceDestruction;
    }
    return m_windowSurface;
}

mini_engine::WindowSurface::~WindowSurface()
{
}

mini_engine::WindowSurface::WindowSurfaceDestruction::~WindowSurfaceDestruction()
{
    if (m_windowSurface != nullptr)
    {
        delete m_windowSurface;
        m_windowSurface = nullptr;
    }
}
